﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace ElectronicJournal.DB
{
    public class DbPatterns
    {
        private SqlDb db;

        public DbPatterns()
        {
            db = new SqlDb();
        }

        public Item.ItemPattern GetPatternInfo(string Id)
        {
            string query = String.Format("SELECT * FROM Patterns WHERE Id = '{0}'", Id);
            DataTable dt = db.Read(query);
            if (dt.Rows.Count > 0)
            {
                return new Item.ItemPattern()
                            {
                                Title = dt.Rows[0]["Title"].ToString(),
                                Description = dt.Rows[0]["Description"].ToString(),
                                FileName = dt.Rows[0]["FileName"].ToString(),
                                Id = dt.Rows[0]["Id"].ToString()
                            };
            
            }
            return null;
        }

        public void ChangePattern(string FileName)
        {
            string query = String.Format("UPDATE Patterns SET FileName = '{0}' WHERE Id = '00000000-0000-0000-0000-000000000000'", FileName);
            db.Query(query);
        }
    }
}